%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% File:               representatives_game2.m
%
% Author:             Miguel R. Rueda and Sergio Ascencio
%
% Description:        Computes structural parameters with two step ML three
% players
%
% Language:           MATLAB R2013b (8.2.0.701) 64 Bit
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [betas,hessian,phats,LL,auxLL,Llong]=representatives_game2(Y,X,state,CLv_PAN,CLv_PRI,CLv_PRD,beta_p)

%First stage results
if state==1
    [phats,~]=first_stage2(Y,X,CLv_PAN,CLv_PRI,CLv_PRD);
else
    [phats,~]=first_stage2(Y,X);
end

%Second stage results
if nargin<7
    [beta,LL,hessian,auxLL,Llong]=Params3(Y,X,phats);
    betas=reshape(beta,[length(beta)/6,6]);
else
    [beta,LL,hessian,auxLL,Llong]=Params3(Y,X,phats,beta_p);
    betas=reshape(beta,[length(beta)/6,6]);
end

end